package com.ruoyi.system.domain.vo.equipment;

import com.fasterxml.jackson.annotation.JsonAlias;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.ruoyi.app.FileObjectDeserializer;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.FileObject;
import com.ruoyi.common.core.domain.JSONObjectPro;
import com.ruoyi.common.core.domain.ParamEntity;
import com.ruoyi.common.utils.DictUtils;
import com.ruoyi.system.domain.DriverInfo;
import com.ruoyi.system.domain.EquipmentManagement;
import com.ruoyi.system.domain.VehicleManagement;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.List;


/**
 * 描述
 * 作者 ZhangPing
 * 创建时间 2023/9/8 16:04
 */
@NoArgsConstructor
@AllArgsConstructor
@Data
@Accessors(chain = true)
public class EquipmentInfo extends ParamEntity {

    /** 设备字段 **/
    @ApiModelProperty("设备ID")
    private Long equipmentId;
    @ApiModelProperty("所属公司id")
    private Long companyId;
    @ApiModelProperty("所属公司名称")
    @Excel(name = "所属公司", sort = 6, width = 30)
    private String companyName;
    @ApiModelProperty("父公司名称")
    private String parentName;
    @ApiModelProperty("设备编号")
    @Excel(name = "设备号", sort = 3)
    private String deviceId;
    @ApiModelProperty("自检状态（0：未自检 1：自检通过 2：自检未通过）")
    private Integer checkStatus;
    @ApiModelProperty("自检详情，英文逗号分隔")
    private String checkDetail;
    @ApiModelProperty("激活状态（0：未激活 1：已激活）")
    private Integer activateStatus;
    @ApiModelProperty("设备型号")
    @JsonFormat(shape = JsonFormat.Shape.STRING)
    @Excel(name = "设备型号", dictType = "deviceModel", type = Excel.Type.IMPORT)
    private Integer deviceModel;
    @ApiModelProperty("视频通道（英文逗号分隔每个通道名称）")
    @JsonAlias({"channelsNum", "channels"})
    private String channels;
    @ApiModelProperty("备注")
    private String remark;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Excel(name = "创建时间", sort = 8, dateFormat = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;

    /** 监管对象字段 **/
    @ApiModelProperty("监管对象ID")
    private Long vehicleId;
    @ApiModelProperty("设备名称")
    @Excel(name = "设备名称", sort = 2)
    private String numberPlate;
    @ApiModelProperty("监管对象颜色")
    private String vehicleColor;
    @ApiModelProperty("监管对象型号")
    private String vehicleModel;
    @ApiModelProperty("监管对象图标")
    private String objIcon;
    @ApiModelProperty("监管类型（字典表配置）")
    @Excel(name = "监管类型", sort = 1, dictType = "objType")
    @JsonFormat(shape = JsonFormat.Shape.STRING)
    private Integer objType;
    @ApiModelProperty("监管对象年龄")
    @JsonAlias({"objAge", "ageVehicle"})
    private Integer objAge;
    @ApiModelProperty("监管对象性别")
    @JsonAlias({"objSex", "ownerSex"})
    private Integer objSex;
    @ApiModelProperty("监管对象联系方式")
    @JsonAlias({"objContactNumber", "contactNumberVehicle"})
    private String objContactNumber;
    @ApiModelProperty("监管对象图片")
    @JsonAlias({"vehiclePic", "vehiclePicStr"})
    @JsonDeserialize(using = FileObjectDeserializer.class)
    private List<FileObject> vehiclePic;

    /** 负责人字段 **/
    @ApiModelProperty("负责人ID")
    private Long driverId;
    @ApiModelProperty("负责人姓名")
    @JsonAlias({"driverName", "name"})
    private String driverName;
    @ApiModelProperty("负责人联系方式")
    @JsonAlias({"driverContactNumber", "contactNumber"})
    private String driverContactNumber;
    @ApiModelProperty("负责人性别")
    private Integer driverSex;
    @ApiModelProperty("负责人年龄")
    @JsonAlias({"driverAge", "age"})
    private Integer driverAge;
    @ApiModelProperty("负责人身份证号")
    @JsonAlias({"driverIdCard","idCard"})
    private String driverIdCard;
    @ApiModelProperty("负责人图片")
    @JsonAlias({"driverPic","driverPicStr"})
    @JsonDeserialize(using = FileObjectDeserializer.class)
    private List<FileObject> driverPic;

    /** SIM卡字段 **/
    @ApiModelProperty("SIM卡号")
    @Excel(name = "SIM卡号", sort = 4)
    private String simId;
    @ApiModelProperty("SIM卡状态")
    @Excel(name = "SIM卡状态", dictType = "accountStatus", sort = 5)
    private String accountStatus;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Excel(name = "入网时间", dateFormat = "yyyy-MM-dd", sort = 7)
    private Date activateTime;
    @ApiModelProperty("激活开始时间")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:dd")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:dd", timezone = "GMT+8")
    @JsonIgnore
    private Date activateStartTime;
    @ApiModelProperty("激活结束时间（yyyy-MM-dd）")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:dd")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:dd", timezone = "GMT+8")
    @JsonIgnore
    private Date activateEndTime;
    @ApiModelProperty("更新时间")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:dd")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:dd", timezone = "GMT+8")
    private Date simUpdateTime;

    @JsonIgnore
    private Boolean numberPlateNotEmpty;
    @JsonIgnore
    private List<Long> companyIds;
    @JsonIgnore
    private List<Integer> objTypes;
    @JsonIgnore
    private String keyWord;

    public EquipmentManagement toEquipment(){
        EquipmentManagement equipment = new EquipmentManagement()
                .setId(equipmentId)
                .setCompanyId(companyId)
                .setDeviceId(deviceId)
                .setSimId(simId)
                .setActivateStatus(activateStatus)
                .setDeviceModel(deviceModel)
                .setChannelsNum(channels);
        equipment.setRemark(remark);
        return equipment;
    }

    public VehicleManagement toObject(){
        return new VehicleManagement()
                .setId(vehicleId)
                .setCompanyId(companyId)
                .setNumberPlate(numberPlate)
                .setVehicleColor(vehicleColor)
                .setVehicleModel(vehicleModel)
                .setVehiclePic(vehiclePic)
                .setObjIcon(objIcon)
                .setObjType(objType)
                .setAge(objAge)
                .setOwnerSex(objSex)
                .setContactNumber(objContactNumber);
    }

    public DriverInfo toDriver(){
        return new DriverInfo()
                .setId(driverId)
                .setCompanyId(companyId)
                .setName(driverName)
                .setContactNumber(driverContactNumber)
                .setPicture(driverPic)
                .setIdCard(driverIdCard)
                .setSex(driverSex)
                .setAge(driverAge);
    }

    public JSONObjectPro toAppModel(){
        JSONObjectPro resJson = new JSONObjectPro()
                .put("equipmentId", equipmentId)
                .put("age", driverAge)
                .put("ageVehicle", objAge)
                .put("channelsNum", channels)
                .put("companyId", companyId)
                .put("companyName", companyName)
                .put("contactNumber", driverContactNumber)
                .put("contactNumberVehicle", objContactNumber)
                .put("deviceId", deviceId)
                .put("deviceModel", deviceModel)
                .put("deviceModelStr", DictUtils.getDictLabel("deviceModel", deviceModel))
                .put("driverId", driverId)
                .put("driverPic", driverPic)
                .put("idCard", driverIdCard)
                .put("name", driverName)
                .put("numberPlate", numberPlate)
                .put("objIcon", objIcon)
                .put("objType", objType)
                .put("objTypeStr", DictUtils.getDictLabel("objType", objType))
                .put("ownerSex", objSex)
                .put("ownerSexStr", DictUtils.getDictLabel("sys_user_sex", objSex))
                .put("sex", driverSex)
                .put("sexStr", DictUtils.getDictLabel("sys_user_sex", driverSex))
                .put("simId", simId)
                .put("vehicleColor", vehicleColor)
                .put("vehicleId", vehicleId)
                .put("vehicleModel", vehicleModel)
                .put("vehiclePic", vehiclePic);
        return resJson;
    }

}
